﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>用户-登录</title>
    <script src="~/Scripts/jquery-1.8.2.min.js"></script>
    <link href="~/Content/css/Login.css" rel="stylesheet" />
    <script type="text/javascript">
        //回车键
        document.onkeydown = function (e) {
            if (!e) e = window.event; //火狐中是 window.event
            if ((e.keyCode || e.which) == 13) {
                var obtnSearch = document.getElementById("btnLog")
                obtnSearch.focus(); //让另一个控件获得焦点就等于让文本输入框失去焦点
                obtnSearch.click();
            }
        }

        function LoginBtn() {
            var name = $("#txtUserName").val();
            var pwd = $("#txtUserPwd").val();
            var code = $("#txtCode").val();
            $("#errorMsg").html("");
            if (name == "") {
                $("#txtUserName").focus();
                $("#errorMsg").html("用户名不能为空!");
                return false;
            } else if (pwd == "") {
                $("#txtUserPwd").focus();
                $("#errorMsg").html("密码不能为空!");
                return false;
            } else if (code == "") {
                $("#txtCode").focus();
                $("#errorMsg").html("验证码不能为空");
                return false;
            } else {
                return true;
            }
        }
        //数据验证完整性
        function CheckUserDataValid() {
            if (!LoginBtn()) {
                return false;
            }
            else {
                var userName = $("#txtUserName").val();
                var userPwd = $("#txtUserPwd").val();
                var code = $("#txtCode").val();
                $.ajax({
                    url: '/Login/Login',
                    type: 'post',
                    data: { loginName: userName, pwd: userPwd, code: code },
                    success: function (jsonData) {
                        if (jsonData.Status == 1) {
                            window.location.href = jsonData.BackUrl;
                        } else {
                            $("#txtUserName").focus();
                            $("#errorMsg").html(jsonData.Msg);
                            ChangeCode();
                            return false;
                        }
                    }
                })
            }
        }

        function ChangeCode() {
            $("#txtCode").val("");
            $("#ImgCode").attr("src", "/Login/CheckCode?time=" + Math.random());
        }
    </script>
</head>
<body>
    <div class='signup_container'>
        <h1 class='signup_title'>用户登陆</h1>
        <div id="signup_forms" class="signup_forms clearfix">
            <div class="signup_form_form">
                <div class="form_row first_row">
                    <label for="signup_email">请输入用户名</label>
                    <input type="text" placeholder="请输入用户名" id="txtUserName">
                </div>
                <div class="form_row">
                    <label for="signup_password">请输入密码</label>
                    <input type="password" onpaste="return false;" id="txtUserPwd" placeholder="请输入密码">
                </div>
                <div class="form_row">
                    <input type="text" id="txtCode" maxlength="5" placeholder="请输入验证码">
                    <img src='/Login/CheckCode' alt="点击切换验证码" title="点击切换验证码" id="ImgCode" onclick="ChangeCode()" />
                </div>
            </div>
        </div>
        <div class="login-btn-set">
            <div id="errorMsg" class='error'></div>
            <a href='javascript:void(0)' id="btnLog" class='login-btn' onclick="return CheckUserDataValid();"></a>
        </div>
    </div>
</body>
</html>